Skip to content

delegation: fix cycles during delayed lowering#154368

Open
aerooneqq wants to merge 7 commits intorust-lang:mainfrom
aerooneqq:delegation-force-lowering-later
Open

delegation: fix cycles during delayed lowering#154368
aerooneqq wants to merge 7 commits intorust-lang:mainfrom
aerooneqq:delegation-force-lowering-later

Conversation

@aerooneqq
Copy link
Copy Markdown
Contributor

@aerooneqq aerooneqq commented Mar 25, 2026

View all comments

This PR forces lowering of delayed owners after hir_crate_items, as some diagnostics use hir_crate_items which results in query cycle which is then hangs calling def_path_str again and again. Fixes #154169. Part of #118212.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 25, 2026
@aerooneqq aerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_lowering delegation: invoke hir_crate_items before force_delayed_owners_lowering Mar 25, 2026
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Mar 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

What specific uses of def_path_str cause the infinite recursion?
Perhaps using something like with_reduced_queries will allow to break the recursion locally, and avoid global changes that this PR does.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 25, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

Relevant - #154387, #154389.

@jyn514
Copy link
Copy Markdown
Member

jyn514 commented Mar 26, 2026

This should really have a reviewer with a lot of query system experience.

r? @Zoxc

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

Failed to set assignee to zoxc: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rust-bors

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the delegation-force-lowering-later branch from f32739b to f50159f Compare March 27, 2026 09:41
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@aerooneqq aerooneqq force-pushed the delegation-force-lowering-later branch from f50159f to 5afd6e4 Compare March 27, 2026 09:50
@aerooneqq
Copy link
Copy Markdown
Contributor Author

So the reason of this cycle was that this function wants to iterate over all free items, however they were not available during delayed lowering as it was executed before hir_crate_items(()), now delayed lowering is executed after hir_crate_items(()), and we use available-without-lowering information to fill hir_crate_items with information about delayed owners.

for id in tcx.hir_free_items() {

Next, there is one more problem in this function, which is maybe not that actual now, but it will be during supporting inherent impls, as during function resolution we will do coherence check, and in cases like:

struct X<T> { t: T }

// No generics provided
impl X {
  pub fn foo() {}
}

reuse X::foo;

we would still come to for_each_def function, but this time this line will be a problem, as we would call delayed lowering during resolution of delegation, so I stored identifier which is needed by this loop in delayed owners, as it once again information that can be accessed without lowering.

let item = tcx.hir_item(id);

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2026
@rust-log-analyzer

This comment has been minimized.

@aerooneqq aerooneqq changed the title delegation: invoke hir_crate_items before force_delayed_owners_lowering delegation: fix cycles during delayed lowering Mar 27, 2026
node => node.ident(),
}
pub fn hir_opt_ident(self, id: HirId) -> Option<Ident> {
self.hir_crate(()).opt_ident(self, id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of hir_crate looks like it may be a source of perf regressions in incremental mode, I'll run benchmarks.

};

let delayed_kinds = tcx.hir_crate(()).delayed_owners_kinds();
let delayed_kinds = delayed_kinds.filter(|(id, _)| match collection_kind {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So calls like tcx.hir_module_items(specific_module) now need to walk the whole crate instead of just specific_module.
Ideally, delayed_ids should perhaps be per-module to fit best into the current setup.
(Not sure if this needs to be addressed right now, perhaps we'll see after running benchmarks.)

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 27, 2026
@aerooneqq
Copy link
Copy Markdown
Contributor Author

aerooneqq commented Mar 27, 2026

@rustbot ready
For perf.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 27, 2026
…<try>

delegation: fix cycles during delayed lowering
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 27, 2026
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 27, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 27, 2026

☀️ Try build successful (CI)
Build commit: 40807f4 (40807f47e0044fa8a906be6caefbfcebd878e621, parent: e3691a5bd58e92999bcbffedf640ecd61e02c29e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (40807f4): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
6.9% [0.3%, 43.4%] 63
Regressions ❌
(secondary)
0.6% [0.0%, 1.1%] 16
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 2
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) 6.7% [-0.2%, 43.4%] 65

Max RSS (memory usage)

Results (primary 6.6%, secondary 2.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.6% [1.2%, 24.4%] 64
Regressions ❌
(secondary)
5.3% [1.4%, 19.8%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.2% [-6.1%, -3.5%] 5
All ❌✅ (primary) 6.6% [1.2%, 24.4%] 64

Cycles

Results (primary 13.2%, secondary 3.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
13.2% [2.0%, 61.2%] 51
Regressions ❌
(secondary)
3.1% [2.7%, 3.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 13.2% [2.0%, 61.2%] 51

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 483.294s -> 485.596s (0.48%)
Artifact size: 395.05 MiB -> 395.15 MiB (0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 27, 2026
@petrochenkov petrochenkov added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 27, 2026
@jyn514
Copy link
Copy Markdown
Member

jyn514 commented Mar 27, 2026

regressions are mostly in evaluate_obligation and typeck. probably they call either ItemCollector::new or hir_opt_ident a lot?

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 28, 2026

☔ The latest upstream changes (presumably #154503) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-fn_delegation `#![feature(fn_delegation)]` perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delegation: oom

6 participants